package repository

import (
	"github.com/gofiber/fiber/v2"
	"gorm.io/gorm"
	"guns-excel/internal/app/model"
)

func GetModels(ctx *fiber.Ctx, dataBaseName string, db *gorm.DB) ([]*model.Tables, error) {
	var tables []*model.Tables
	if err := db.Raw("SELECT table_schema, table_name FROM information_schema.TABLES WHERE table_schema = ?", dataBaseName).Scan(&tables).Error; err != nil {
		return nil, err
	}
	return tables, nil
}

func GetFieldByTableName(ctx *fiber.Ctx, dataBaseName, tableName string, db *gorm.DB) (*[]model.TableField, error) {
	var tableField []model.TableField
	if err := db.Raw("select column_name,data_type,column_comment,table_schema,table_name  from information_schema.columns where TABLE_NAME=? AND table_schema = ?", tableName, dataBaseName).Scan(&tableField).Error; err != nil {
		return nil, err
	}
	return &tableField, nil
}
